package org.jsola.contract.query;

import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import org.jsola.contract.constant.ContractType;
import org.jsola.contract.constant.FileType;
import org.jsola.contract.constant.SealType;
import org.jsola.core.query.BaseQuery;
import org.jsola.orm.filter.Order;
import org.springframework.util.CollectionUtils;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static org.jsola.contract.example.ContractExample.*;

/**
 * 合同导出列表
 *
 * @author wcl
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class ContractExportQuery extends BaseQuery {

    private static final long serialVersionUID = 1L;

    @ApiParam(value = N_SIGN_NO, example = E_SIGN_NO)
    @Length(max = 20)
    private String signNo;

    @ApiParam(value = N_SUBJECT_ID, example = E_SUBJECT_ID, required = true)
    private String subjectId;

    @ApiParam(value = N_SUBJECT_ID, example = E_SUBJECT_ID, required = true)
    private List<String> subjectIds;

    @ApiParam(value = N_NAME, example = E_NAME)
    @Length(max = 255)
    private String name;

    @ApiParam(value = N_STATUS, example = E_STATUS)
    private Integer status;

    @ApiParam(value = N_FILE_TYPE, example = E_FILE_TYPE, allowableValues = FileType.VALUES_STR)
    @Length(max = 50)
    private String fileType;

    @ApiParam(value = N_APP_IS_SHOW, example = E_APP_IS_SHOW)
    private Boolean appIsShow;

    @ApiParam(value = "签署编号/合同名称/员工姓名/员工手机号")
    private String signNoOrContractNameOrEmpIdOrEmpPhone;

    @ApiParam(value = "排序字段", allowMultiple = true, type = "Order", example = "\"orders\": [{\"property\": \"userName\",\"desc\": false}]")
    private List<Order> orders;

    @ApiParam(value = "合同id集合")
    private List<Long> contractIdList;

    /**
     * 添加排序
     *
     * @param propertyName 属性名
     * @param desc         是否降序
     * @return this
     */
    public ContractExportQuery addOrder(String propertyName, boolean desc) {
        if (CollectionUtils.isEmpty(this.orders)) {
            this.orders = new ArrayList<>();
        }
        this.orders.add(new Order(propertyName, desc));
        return this;
    }

}

